The ForEach component renders a dynamic list of child views. It is used to display collections, create editable lists, and enable system-standard interactions such as swipe-to-delete. It is fully integrated with the Scripting app’s Observable state system and mirrors the design of SwiftUI’s ForEach.
ForEach supports two usage modes:
count + itemBuilderdata: Observable<T[]> + builderSpecifies how many items to render. The itemBuilder function will be called for indices from 0 to count - 1.
Builds a VirtualNode for each index.
Enables system-standard swipe-to-delete when the ForEach is placed inside a List.
This callback is invoked after the row has already been removed from the list UI.
You must manually delete the corresponding items from your data source inside this callback.
Enables drag-to-reorder behavior.
To disable item movement, pass null.
An observable array of items.
Each item must contain a unique id: string.
Benefits of using Observable<T[]>:
ForEach($items)List, NavigationStack, and other componentsBuilds a VirtualNode for the element at the given index.
Important: You must provide a unique key (usually item.id) on the returned node.
Defines the editing capabilities of the ForEach component.
| Value | Description |
|---|---|
"delete" |
Enables deletion only |
"move" |
Enables reordering only |
"all" |
Enables both deletion and movement |
null |
No editing actions (default) |
When used inside a List, these actions automatically map to system-standard interactions.
The component is generic and supports any item type containing an id.
When ForEach is placed inside a List, using data and builder will automatically activate swipe-to-delete. The only requirement is that each item has a unique id.
data: Observable<T[]> APIThis mode provides:
id: stringThis ensures:
key={item.id} in the builderFailing to do so may result in:
ListAnd optionally add an EditButton, for example: